<?php
class ViewPrintCategory extends View_Admin_Index_Template {
    private $page = 0;
    private $pageSize = 28;
    public $oTemp;
    public function __construct($oModel) {
        $this->initTemplate($oModel);
        // $this->oTemp->assign_file('tempMainContent', PATH_TEMPLATE_ADMIN . 'html/category_management_index.html');
        $this->oTemp->assign('pageHeding', $oModel->aLanguage[MODULE_HEADING]['category']);
    /**
     * toolbar setup
     */
    // $this->oTemp->assign('toobar_print', 'javascript:printLabel()');
    //$this->oTemp->parse('main.toobar_print');
    }

    public function displaySelectPage($oModel) {

        $this->oTemp->assign_file('tempMainContent', PATH_TEMPLATE_ADMIN .'html/print_category.html');

        $default_category_id = 23416;
        $userID = 0;
        if($_SESSION['admin_role']==3){
            $userID = $_SESSION['admin_id'];
            $this->oTemp->assign("shop_owner_id",$_SESSION['admin_id']);
            $this->oTemp->parse("main.shop_owner_role");
        }
        else{
            $userID = $_GET['userID'];
            $rs = $oModel->getAllShopOwner();
            foreach($rs as  $row){
                if($row['admin_id']==$userID){
                    $row['admin_select']='selected="selected"';
                }
                else{
                    $row['admin_select']='';
                }
                $this->oTemp->assign("admin",$row);
                $this->oTemp->parse("main.admin_role.shop_owner");
            }
            $this->oTemp->parse("main.admin_role");
        }
        $userInfo = $oModel->getUserInfo($userID);
        if(!$userInfo){
            return false;
        }
        
        $default_category_id = $userInfo['admin_category_id'];

        $oModel->setDefaultCategory($default_category_id);

        $topCate=$oModel->getTopCategory();
        if(is_array($topCate)) {
            foreach($topCate as $row) {
                $this->oTemp->assign("topCate",$row);
                $this->oTemp->parse("main.top_panel");
                $listChild=$oModel->getListChildOnly($row['product_category_id']);
                if(is_array($listChild)) {
                    $this->oTemp->assign("isBrand","1");
                    foreach($listChild as $childRow) {
			if($oModel->checkParentID($childRow['product_category_id'])) {
                            $childRow['product_category_name']='<a href="#"> '.$childRow['product_category_name']." </a>";
                            $childRow['javaFunction'] = "loadChildTab(0,'".$childRow['product_category_id']."','1')";
                        }
                        else {
                            $childRow['javaFunction'] = "selectCate(this,'".$childRow['product_category_yahoo_id']."')";
                        }
                        $this->oTemp->assign("list",$childRow);
                        $this->oTemp->parse("main.detail.list");
                    }
                }
                $this->oTemp->assign("detail",$row);
                $this->oTemp->parse("main.detail");
            }
        }
        /*
        $leftCate=$oModel->getLeftCategory();
        if(is_array($leftCate)) {
            foreach($leftCate as $row) {

                $listChild=$oModel->getListChildOnly($row['product_category_id']);
                if(is_array($listChild)) {
                    $this->oTemp->assign("isBrand","0");
                    foreach($listChild as $childRow) {
		        $row['first_product_category_id'] = $childRow['product_category_id'];
                        break;
                    }

                }
                $this->oTemp->assign("leftCate",$row);
                $this->oTemp->parse("main.left_panel");

                $this->oTemp->assign("detail",$row);
                $this->oTemp->parse("main.detail_alphabet");
            }
        }
         * */
        $this->oTemp->assign("default_category_id",$default_category_id);
    }
    public function loadChildCategory($oModel) {
        $xtpl=new XTemplate(PATH_TEMPLATE_ADMIN .'html/print_category_childTab.html');
        $cID=$_REQUEST['cID'];
        $level=$_REQUEST['level'];
        $isBrand=$_REQUEST['isBrand'];
        $xtpl->assign("level",$level);
        $detail=$oModel->getInfoCategory($cID);
        $listChild=$oModel->getListChildOnly($cID);
        if(is_array($listChild)) {
            $xtpl->assign("isBrand",$isBrand);
            foreach($listChild as $row) {

                if($oModel->checkParentID($row['product_category_id'])) {
                    $row['product_category_name']='<a href="#"> '.$row['product_category_name']." </a>";
                    $row['javaFunction']="loadChildTab(".$level.",'".$row['product_category_id']."','".$isBrand."')";
                //$xtpl->parse("detail.list");
                }
                else {
                    $row['javaFunction']="selectCate(this,'".$row['product_category_yahoo_id']."')";
                //$xtpl->parse("detail.list_notChild");
                }
                $xtpl->assign("list",$row);
                $xtpl->parse("detail.list");
            }
            $xtpl->assign("brandTab",$isBrand);
            $xtpl->assign("detail",$detail);
            if($_REQUEST['isBrand']==1) {
                $arrBrands=$oModel->getBrands4Category($detail['product_category_name']);
                if(is_array($arrBrands)&& $arrBrands[0][brandID]!="") {

                    $xtpl->parse("detail.break");
                    $count=count($arrBrands);
                    if($count>$this->pageSize) {
                        $pageOne=$this->pageSize;
                    }
                    else {
                        $pageOne=$count;
                    }
                    for($i=0;$i<$pageOne;$i++) {
                        $brand = $arrBrands[$i];
                        $brandDetail=$oModel->getInfoCategory($brand['brandID']);
                        $brandChild=$oModel->getInfoCategory($brand['childID']);
                        $brandChild['product_category_name']=$brandDetail['product_category_name'];
                        $xtpl->assign("list",$brandChild);
                        if($oModel->checkParentID($brandChild['product_category_id'])) {
                            $xtpl->parse("detail.brand");
                        }
                        else {
                            $xtpl->parse("detail.brand_notChild");
                        }
                    }
                }
            }
            $xtpl->assign("pages",$this->PageNav($count,$this->pageSize,1,$cID,$level));
            $xtpl->parse("detail");
            echo $xtpl->text("detail");

            //print_r($arrBrands);
            exit();
        }


    }

    public function loadAlphabetCategory($oModel) {
        $xtpl=new XTemplate(PATH_TEMPLATE_ADMIN .'html/print_category_AlphabetTab.html');
        $cID=$_REQUEST['cID'];
        $level=$_REQUEST['level'];
        $isBrand=$_REQUEST['isBrand'];
        $xtpl->assign("level",$level);
        $detail=$oModel->getInfoCategory($cID);
        $listChild=$oModel->getListChildOnly($cID);
        if(is_array($listChild)) {
            $xtpl->assign("isBrand",$isBrand);
            foreach($listChild as $row) {

                if($oModel->checkParentID($row['product_category_id'])) {
                    $row['product_category_name']='<a href="#"> '.$row['product_category_name']." </a>";
                    $row['javaFunction']="loadChildTab(".$level.",'".$row['product_category_id']."','".$isBrand."')";
                //$xtpl->parse("detail.list");
                }
                else {
                    $row['javaFunction']="selectCate(this,'".$row['product_category_yahoo_id']."')";
                //$xtpl->parse("detail.list_notChild");
                }
                $xtpl->assign("list",$row);
                $xtpl->parse("detail.list");
            }
            $listAlphabet=$oModel->getListChildOnly($detail['product_category_parent_id']);
            if(is_array($listAlphabet)) {
                foreach($listAlphabet as $alphabet) {
                    if($oModel->checkParentID($alphabet['product_category_id'])) {
                        $alphabet['product_category_name'] = '<a>'.$alphabet['product_category_name'].'</a>';
                        if($alphabet['product_category_id'] == $cID) {
                            $alphabet['focus'] = 'category_tab_focus';
                        }
                        else {
                            $alphabet['focus']='';
                        }
                        $alphabet['javaFunction']="loadAlphabetTab(0,'".$alphabet['product_category_id']."','0')";

                    }
                    else {
                        $alphabet['javaFunction']="selectCate(this,'".$alphabet['product_category_yahoo_id']."')";
                    }
                    $xtpl->assign("detail",$alphabet);
                    $xtpl->parse("detail.alphabet_tab");
                }
            }
            $xtpl->parse("detail");
            echo $xtpl->text("detail");
            exit();
        }


    }

    public function loadCurrentTab($oModel) {
        $xtpl=new XTemplate(PATH_TEMPLATE_ADMIN .'html/print_category_current_tab.html');
        $cID=$_REQUEST['cID'];
        $level=$_REQUEST['level'];
        $isBrand=$_REQUEST['isBrand'];
        $xtpl->assign("level",$level);
        $detail = $oModel->getInfoCategory($cID);
        $listChild=$oModel->getListChildOnly($cID);
        if(is_array($listChild)) {
            $xtpl->assign("isBrand",$isBrand);
            foreach($listChild as $row) {
	        if($oModel->checkParentID($row['product_category_id'])) {
                    $row['product_category_name'] = "<a>".$row['product_category_name']."</a>";
                    $row['javaFunction'] = "loadChildTab(".$level.",'".$row['product_category_id']."','".$isBrand."')";
                }else {
                    $row['javaFunction'] = "selectCate(this,'".$row['product_category_yahoo_id']."')";
                }
                $xtpl->assign("list",$row);
                $xtpl->parse("main.list");
            }
            if($isBrand==1) {
                $arrBrands=$oModel->getBrands4Category($detail['product_category_name']);
                if(is_array($arrBrands)&& $arrBrands[0][brandID]!="") {
                    $xtpl->parse("main.break");
                    $count=count($arrBrands);
                    if($count>$this->pageSize) {
                        $pageOne=$this->pageSize;
                    }
                    else {
                        $pageOne=$count;
                    }
                    for($i=0;$i<$pageOne;$i++) {
                        $brand = $arrBrands[$i];
                        $brandDetail=$oModel->getInfoCategory($brand['brandID']);
                        $brandChild=$oModel->getInfoCategory($brand['childID']);
                        $brandChild['product_category_name']=$brandDetail['product_category_name'];
                        $xtpl->assign("list",$brandChild);
                        if($oModel->checkParentID($brandChild['product_category_id'])) {
                            $xtpl->parse("main.brand");
                        }
                        else {
                            $xtpl->parse("main.brand_notChild");
                        }
                    }
                }
            }
            $xtpl->assign("pages",$this->PageNav($count,$this->pageSize,1,$cID,$level));
            $xtpl->parse("main");
            echo $xtpl->text("main");
            exit();
        }
    }
    public function loadPageNav($oModel) {
        $xtpl=new XTemplate(PATH_TEMPLATE_ADMIN .'html/print_category_page_nav.html');
        $cID=$_REQUEST['cID'];
        $page=$_REQUEST['page'];
        $level=$_REQUEST['level'];
        $xtpl->assign("level",$level);
        $detail=$oModel->getInfoCategory($cID);
        $arrBrands=$oModel->getBrands4Category($detail['product_category_name']);
        if(is_array($arrBrands)&& $arrBrands[0][brandID]!="") {
            $count=count($arrBrands);
            if($page==0 || $page=='') {
                $this->page=1;
            }
            else {
                $this->page=$page;
            }
            $count=count($arrBrands);
            if($count>$this->pageSize*$this->page) {
                $endPage=$this->page*$this->pageSize;
            }
            else {
                $endPage=$count;
            }
            $startPage=($this->page-1)*$this->pageSize;
            //echo $startPage." - ".$endPage;
            for($i=$startPage;$i<$endPage;$i++) {
                $brand = $arrBrands[$i];
                $brandDetail=$oModel->getInfoCategory($brand['brandID']);
                $brandChild=$oModel->getInfoCategory($brand['childID']);
                $brandChild['product_category_name']=$brandDetail['product_category_name'];
                $xtpl->assign("list",$brandChild);
                if($oModel->checkParentID($brandChild['product_category_id'])) {
                    $xtpl->parse("main.brand");
                }
                else {
                    $xtpl->parse("main.brand_notChild");
                }
            }
        }
        $xtpl->assign("pages",$this->PageNav($count,$this->pageSize,$this->page,$cID,$level));
        $xtpl->parse("main");
        echo $xtpl->text("main");
        exit();
    }
    public function PageNav($total,$pageSize,$page,$cID,$level) {
        if($total%$pageSize>0) {
            $pageNum=floor($total/$pageSize)+1;
        }
        else {
            $pageNum=floor($total/$pageSize);
        }
        $text="";
        if($pageNum==1)
            return "";
        for($i=1;$i<=$pageNum;$i++) {
            if($i==$page) {
                $text .= '&nbsp;&nbsp;'.$i.'&nbsp;&nbsp;';
            }
            else {
                $text .= '<a onClick="PageNav('.$i.','.$cID.','.$level.')">'.$i.'</a>';
            }
        }
        return $text;
    }
    private function getAllCat($oModel,$xtpl,$row) {
        $listChild=$oModel->getListChildOnly($row['product_category_id']);
        if(is_array($listChild)) {
            $arr=array();
            $i=0;
            foreach($listChild as $childRow) {
                $arr[$i]=$childRow;
                $i++;
                $this->getAllCat($oModel,$xtpl,$childRow);
            }
            foreach($arr as $cRow) {
                $xtpl->assign("list",$cRow);
                $xtpl->parse("main.detail.list");
            }
            $xtpl->assign("detail",$row);
            $xtpl->parse("main.detail");
        }

    }
    public function displayListCategoryNew($oModel) {
        $rs = $oModel->getListParentCategory();
        if (is_array($rs)) {
            $i = 0;
            foreach ($rs as $row) {
                $i++;
                $row['no'] = $i;
                $row['css'] = "row" . ($i % 2);
                $row['prefix'] = $this->displayTreePrefixImg(1);
                if ($row['product_category_status'] == 1) {
                    $row['product_category_status'] = 'checked';
                }

                if ($row['product_category_statistics'] == 1) {
                    $row['product_category_statistics'] = 'checked';
                }

                if ($_SESSION['category_change_igm_id'] != '' && $_SESSION['category_change_igm_id'] ==
                    $row['product_category_id']) {

                    $category_image_old = $row['product_category_image'];
                    $oModel->deleteThumbImage($category_image_old);
                }
                $row['product_category_image_thumb'] = $oModel->getThumbImage($row['product_category_image'],
                    20, 20);

                $row['level']=0;

                $row['display_product_category_name']="<a href='?sMod=category_index&sAction=list_child&cat_id={rowCategory.product_category_id}&cat_name=".$row['product_category_name']."&current_level=".$row['level']."'>".$row['product_category_name']."</a>";

                $this->oTemp->assign('rowCategory', $row);
                $this->oTemp->parse('main.rowCategory');
            }
        }
        else {
            $this->oTemp->parse('main.no_found');
        }
    //$this->oTemp->assign('navigator', $oModel->oNavigator->navigator());
    }
    public function displayListCategory($oModel) {
        $rs = $oModel->getListParentCategory();
        if (is_array($rs)) {
            $i = 0;
            foreach ($rs as $row) {
                $i++;
                $row['no'] = $i;
                $row['css'] = "row" . ($i % 2);
                //$row['prefix'] = $this->displayTreePrefixImg($row['category_level']);
                if ($row['product_category_status'] == 1) {
                    $row['product_category_status'] = 'checked';
                }
                //                $row['product_category_description'] = preview_text($row['product_category_description'],
                //                    50);
                //                if ($_SESSION['category_change_igm_id'] != '' && $_SESSION['category_change_igm_id'] ==
                //                    $row['product_category_id'])
                //                {
                //
                //                    $category_image_old = $row['product_category_image'];
                //                    $oModel->deleteThumbImage($category_image_old);
                //                }
                //
                //
                //                $row['product_category_image_thumb'] = $oModel->getThumbImage($row['product_category_image'],
                //                    20, 20);
                $this->oTemp->assign('rowCategory', $row);
                $this->oTemp->parse('main.rowCategory');
                $this->getAllChild($oModel,$row['product_category_id'],$level);
            }
        }
        else {
            $this->oTemp->parse('main.no_found');
        }
    //$this->oTemp->assign('navigator',$oModel->oNavigator->navigator());
    }

    public function getAllChild($oModel,$parent_id,$level) {
        $rs=$oModel->getListChildOnly($parent_id);
        if(is_array($rs)) {
            $level++;
            foreach($rs as $row) {
                $row['product_category_name']=str_repeat("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;",$level).$row['product_category_name'];
                if ($row['product_category_status'] == 1) {
                    $row['product_category_status'] = 'checked';
                }
                $this->oTemp->assign('rowCategory', $row);
                $this->oTemp->parse('main.rowCategory');
                $this->getAllChild($oModel,$row[product_category_id],$level);
            }
        }
    }

    /**
     * DISPLAY CATEGORY LIKE OS COMMERCE()
     */
    public function displayListChildCategory($oModel) {
        $parent_id=$oModel->getData('parent_category_id');
        $rs=$oModel->getListChildOnly($parent_id);
        if(is_array($rs)) {
            foreach($rs as $row) {
                $current_level = $oModel->getData('current_level');
                $row['level'] = $current_level + 1;

                $i++;
                $row['no'] = $i;
                $row['css'] = "row" . ($i % 2);
                $rs_check_child=$oModel->getListChildOnly($row['product_category_id']);


                if(is_array($rs_check_child)) {
                    $row['prefix'] = "<img src='{URL_TEMPLATE_ADMIN}image/tree_img/folder.gif'/>";
                    $row['display_product_category_name']=
                        "<a href='?sMod=category_index&sAction=list_child&cat_id=".$row['product_category_id']."&cat_name=".$row['product_category_name']."&current_level=".$row['level']."'>".$row['product_category_name']."</a>";

                }
                else {
                    $row['prefix'] = "<img src='{URL_TEMPLATE_ADMIN}image/tree_img/page.gif'/>";
                    $row['display_product_category_name']="
					<a href='?sMod=category_index&sAction=edit_form&id=".$row['product_category_id']."'>".$row['product_category_name']."</a>";
                }


                if ($row['product_category_status'] == 1) {
                    $row['product_category_status'] = 'checked';
                }

                if ($row['product_category_statistics'] == 1) {
                    $row['product_category_statistics'] = 'checked';
                }

                if ($_SESSION['category_change_igm_id'] != '' && $_SESSION['category_change_igm_id'] ==
                    $row['product_category_id']) {

                    $category_image_old = $row['product_category_image'];
                    $oModel->deleteThumbImage($category_image_old);
                }
                $row['product_category_image_thumb'] = $oModel->getThumbImage($row['product_category_image'],
                    20, 20);



                $this->oTemp->assign('rowCategory', $row);
                $this->oTemp->parse('main.rowCategory');
            }
        }
        else {
            $this->oTemp->parse('main.no_found');
        }
        //DISPLAY PATH CAT
        $level=$current_level;
        $rs_path_cat=$_SESSION['path_cat'];
        $count=$rs_path_cat;
        if(is_array($rs_path_cat)) {

            if($rs_path_cat[$level]['cat_id']!=$_GET['cat_id']) {
                $_SESSION['path_cat'][$level]=$_GET;
            }

            foreach($_SESSION['path_cat'] as $row_path_cat) {
                if($row_path_cat['current_level']>$_GET['current_level']) {
                    $_SESSION['path_cat'][$num_row]=null;
                }
                $num_row++;
            }
        }
        else {
            $_SESSION['path_cat'][$level]=$_GET;
        }
        //////////////////////////////////
        $rs_path_cat=$_SESSION['path_cat'];
        foreach($rs_path_cat as $row_path_cat) {
            if($row_path_cat!=null) {
                $row_path_cat['display_category_name']="<a href='?sMod=category_index&sAction=list_child&cat_id=".$row_path_cat['cat_id']."&cat_name=".$row_path_cat['cat_name']."&current_level=".$row_path_cat['current_level']."'>".$row_path_cat['cat_name']."</a>";
                $this->oTemp->assign('rowPathCat',$row_path_cat);
                $this->oTemp->parse('main.rowPathCat');
            }
        }
    }
    /**
     * ADD NEW CATEGORY
     */
    public function displayNewCategoryIndex($oModel) {
        $this->initTemplate($oModel);
        $this->oTemp->assign_file('tempMainContent', PATH_TEMPLATE_ADMIN .'html/category_mamagement_new.html');
        $this->oTemp->assign_file('temp_editor', PATH_TEMPLATE_ADMIN .'html/temp_editor_product.html');
        $this->oTemp->assign('pageHeding', $oModel->aLanguage[MODULE_HEADING]['category']);

        /**
         * toolbar setup
         */
        $this->oTemp->assign('product_category_status', 'checked');
        $this->oTemp->assign('toobar_save', 'check_cat_form()');
        $this->oTemp->parse('main.toobar_save');
        $this->oTemp->assign('toobar_cancel', '?sMod=category_index');
        $this->oTemp->parse('main.toobar_cancel');
    }
    public function displayBoxCategoryParent($oModel) {
        $rsSiteMap = $oModel->getListCategoryParentChild();
        if (is_array($rsSiteMap)) {
            $i = 0;
            foreach ($rsSiteMap as $rowSiteMap) {
                $i++;
                $rowSiteMap['no'] = $i;
                if ($rowSiteMap['product_category_id'] == $oModel->getData('product_category_parent_id')) {
                    $rowSiteMap['selected'] = 'selected';
                }
                $rowSiteMap['prefix'] = $this->displayTreePrefix($rowSiteMap['category_level']);
                $this->oTemp->assign('rowCatParent', $rowSiteMap);
                $this->oTemp->parse('main.rowCatParent');
            }
        }
    }
    private function displayTreePrefix($level) {
        $sPrefix = "";
        for ($i = 1; $i < $level; $i++) {
            $sPrefix .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|";
        }
        $sPrefix .= "&nbsp;";
        return $sPrefix;
    }
    private function displayTreePrefixImg($level) {
    //$sPrefix = "|";
        if ($level == 1)
            $sPrefix = "<img src='{URL_TEMPLATE_ADMIN}image/tree_img/folder.gif'/>";
        else {
            for ($i = 1; $i < $level; $i++) {
                $sPrefix .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
            }
            $sPrefix .= "<img src='{URL_TEMPLATE_ADMIN}image/tree_img/page.gif'/>&nbsp;";
        }
        //$sPrefix .= "____";*/
        //else
        //$sPrefix= URL_TEMPLATE_ADMIN.'image/tree_img/child.gif';
        return $sPrefix;
    }
    /**
     * EDIT CATEGORY
     */
    public function displayEditCategoryIndex($oModel) {
        $this->initTemplate($oModel);
        $this->oTemp->assign_file('tempMainContent', PATH_TEMPLATE_ADMIN .
            'html/category_management_edit.html');
        $this->oTemp->assign_file('temp_editor', PATH_TEMPLATE_ADMIN .
            'html/temp_editor_basic.html');
        $this->oTemp->assign('pageHeding', $oModel->aLanguage[MODULE_HEADING]['category']);
        /**
         * toolbar setup
         */
        $this->oTemp->assign('toobar_save', 'check_edit_cat_form()');
        $this->oTemp->parse('main.toobar_save');
        $this->oTemp->assign('toobar_cancel', '?sMod=category_index');
        $this->oTemp->parse('main.toobar_cancel');
    }

    public function displayInfoCat($rowManager,$oModel) {
        if ($rowManager['product_category_status'] == 1)
            $rowManager['product_category_status'] = "checked";
        $rowManager['product_category_yahoo_id_old'] = $rowManager['product_category_yahoo_id'];

        $rowParent = $oModel->getInfoCategory($rowManager['product_category_parent_id']);
        if(is_array($rowParent)) {
            $rowManager['product_category_parent_name']=$rowParent['product_category_name'];
        }
        else
            $rowManager['product_category_parent_name']=$oModel->aLanguage["CATEGORY"]['root'];

        $this->assignExtract($rowManager);
    }

    public function resultXML($oModel, $cCMD, $cResult) {
        $oJSON = new Services_JSON();
        echo $oJSON->encode(array('HEAD' => array('CMD' => $cCMD, 'DATA' => date('d/m/Y H:m:s'), ),
        'BODY' => array('RES' => $cResult)));
    }

    /*************************************************************************************************
    CATEGORY CHOOSE
    *************************************************************************************************/
    public function displatChooseCategoryIndex($oModel) {
        $this->initTemplate($oModel);
        $this->oTemp->assign_file('tempMainContent', PATH_TEMPLATE_ADMIN .
            'html/category_choose.html');

        $this->oTemp->assign('pageHeding', $oModel->aLanguage['MENU']['choose_category']);

        /**
         * toolbar setup
         */

        $this->oTemp->assign('toobar_print', 'check_form()');
        $this->oTemp->parse('main.toobar_print');
        $this->oTemp->assign('toobar_cancel', '?sMod=category_index');
        $this->oTemp->parse('main.toobar_cancel');
    }


    public function ajax_displayListParentCategory($oModel) {

        $rs = $oModel->getListParentCategoryChoose();
        if (is_array($rs)) {
            $num_row = 0;
            foreach ($rs as $row) {
                $rs_child = $oModel->getListChildOnly($row['product_category_id']);
                if (is_array($rs_child)) {
                //$row['parent_img'] = URL_TEMPLATE_ADMIN . "image/arrow.gif";
                    $row['parent_img']='blue';
                }
                else
                //$row['parent_img'] =	URL_TEMPLATE_ADMIN . "image/blank.png";
                    $row['parent_img']='#999999';


                $row['highlight'] = "";
                $row['row_id'] = 0;
                $row['num_row'] = "parent" . $num_row;

                $this->oTemp->assign('i',$num_row%2);
                $num_row++;

                $this->oTemp->assign('RowCat', $row);
                $this->oTemp->parse('main.ResultCat.RowCat');
            }
            $this->oTemp->assign('row_id', 0);
            $this->oTemp->parse('main.ResultCat');
        }
        return $this->oTemp->text('main.ResultCat');
    }

    public function ajax_displayListChildCateogry($oModel, $parent_id) {
        $rs = $oModel->getListChildCategoryChoose($parent_id);
        $current_level = $oModel->getData('current_level');
        $next_level = $current_level + 1;
        //$_SESSION['test_count']=$next_level;

        if (is_array($rs)) {
            $num_row=0;
            foreach ($rs as $row) {
                $rs_child = $oModel->getListChildCategoryChoose($row['product_category_id']);

                if (is_array($rs_child)) {
                //$row['parent_img'] = URL_TEMPLATE_ADMIN . "image/arrow.gif";
                    $row['parent_img']='blue';
                }
                else
                //$row['parent_img'] =	URL_TEMPLATE_ADMIN . "image/blank.png";
                    $row['parent_img']='#999999';

                $row['num_row'] = $next_level."_child" . $num_row;
                $num_row++;

                $row['row_id'] = $next_level;

                $this->oTemp->assign('i',$num_row%2);
                $num_row++;

                $this->oTemp->assign('RowCat', $row);
                $this->oTemp->parse('main.ResultCat.RowCat');
            }
            $this->oTemp->assign('row_id', $next_level);
            $this->oTemp->parse('main.ResultCat');
        }
        $aResult[0]=$this->oTemp->text('main.ResultCat');
        $aResult[1]=$next_level;
        return $aResult;
    }
}
